package com.demo.partition;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class FlowDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        //获取job
        Configuration conf =new Configuration();
        Job job = Job.getInstance(conf);
        //设置jar
        job.setJarByClass(FlowDriver.class);
        //关联map和reduce
        job.setMapperClass(FlowMapper.class);
        job.setReducerClass(FlowReducer.class);
        //设置map的输出key和value
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(FlowBean.class);
        //设置reduce的输出key和value
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(FlowBean.class);

        job.setPartitionerClass(ProvincePartition.class);
        job.setNumReduceTasks(5);
        //设置数据输入和输出路径
        FileInputFormat.setInputPaths(job,new Path("D:\\Code\\JavaCode\\MapReduceDemo\\test_data\\in\\partition"));
        FileOutputFormat.setOutputPath(job,new Path("D:\\Code\\JavaCode\\MapReduceDemo\\test_data\\out\\partition"));
        //提交job
        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);
    }
}
